<?php
/**
 * FastApp.
 * 8/13/24
 * @Author 深色的海 (wx:deepsea_0024)
 * @Contact telegram:deepsea159
 */

namespace App\Fastapp\Api\Controller\Pay;

use App\Fastapp\Api\Controller\ApiController;
use App\Fastapp\Api\Service\Pay\PayService;
use App\Fastapp\Aspect\ApiAuth;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;


#[Controller('api/pay'), ApiAuth]
class PayController extends ApiController
{
    #[Inject]
    public PayService $service;

    #[GetMapping('platform')]
    public function platform(): ResponseInterface
    {
        return $this->success($this->service->platform());
    }

    #[GetMapping('platformWithdrawal')]
    public function platformWithdrawal(): ResponseInterface
    {
        return $this->success($this->service->platformWithdrawal());
    }

    #[PostMapping('recharge')]
    public function recharge(): ResponseInterface
    {
        $this->validate([
            'symbol' => 'required',
            'amount' => 'required',
            'code' => 'required',
        ]);
        return $this->success($this->service->recharge($this->request->all()));
    }

    #[PostMapping('withdrawal')]
    public function withdrawal(): ResponseInterface
    {
        return $this->service->withdrawal($this->validate([
            'code' => 'required',
            'symbol' => 'required',
            'amount' => 'required',
            'pay_info_id' => 'required',
            'password' => 'required',
        ])) ? $this->success() : $this->error();
    }
}